package com.javatest2;

import java.util.Arrays;

/**
 * @author LL
 * 选择排序法(寻找最小的数字在左边)
 * @create 2021-01-19 17:53
 */
public class Subject7 {

    public static void test(final int[] a) {
        for (int i = 0; i < a.length - 1; i++) {
            int minIndex = i;
            for (int j = i + 1; j < a.length; j++) {
                if (a[j] < a[minIndex]) {
                    minIndex = j;
                }
            }
            if (i != minIndex) {
                final int temp = a[i];
                a[i] = a[minIndex];
                a[minIndex] = temp;
            }
        }
        System.out.println(Arrays.toString(a));
    }

    public static void main(final String[] args) {
        final int[] a = {12, 4, 3, 78, 34, 90, 2, 5, 3, 0, 7, 4, 8, 9};
        test(a);
    }
}
